package com.example.recall_application.utils;

import android.content.Context;
import android.os.Handler;
import android.provider.CallLog;

import com.example.recall_application.mvp.entity.CallLogItem;

import java.util.ArrayList;
import java.util.List;

public final class CallLogHelper extends ResolverHelperImpl<List<String>> {

    public CallLogHelper(Context context, Handler handler,String condition) {
        super(context, handler,condition);
        mData = new ArrayList<>();
    }

    @Override
    public void initParams() {
        contentUri = CallLog.Calls.CONTENT_URI;
        mColumns = new String[]{
                CallLog.Calls.NUMBER,/*手机号*/
                CallLog.Calls.CACHED_NORMALIZED_NUMBER,/*格式化手机号*/
                CallLog.Calls.CACHED_NAME,/*匹配通讯录的名称*/
                CallLog.Calls.DATE,/*通话日期*/
                CallLog.Calls.DURATION,/*通话时长，秒数*/
                CallLog.Calls.TYPE,/*1来电，2拨出，3未接*/
                CallLog.Calls.VOICEMAIL_URI,/*语音地址*/
                CallLog.Calls.GEOCODED_LOCATION,/*号码归属地*/
                CallLog.Calls.COUNTRY_ISO,/*国家简称CN,US等*/
                CallLog.Calls.PHONE_ACCOUNT_ID/*SIM卡标记，用来区分是否是双卡手机*/
        };
    }

    @Override
    public void parseData() {
        while (mCursor != null && mCursor.moveToNext()) {
            try {

                String number = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.NUMBER));
//                String formatNumber = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.CACHED_NORMALIZED_NUMBER));
//                String name = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
//                String date = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.DATE));
//                String duration = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.DURATION));
//                String type = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.TYPE));
//                String voicemailUri = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.VOICEMAIL_URI));
//                String geo = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.GEOCODED_LOCATION));
//                String iso = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.COUNTRY_ISO));
//                String imsi = mCursor.getString(mCursor.getColumnIndex(CallLog.Calls.PHONE_ACCOUNT_ID));

//                log.setFormatNumber(formatNumber);
//                log.setName(name);
//                log.setDate(DateUtils.getFormatTimeFromMillis(Long.parseLong(date)));
//                log.setDuration(duration);
//                log.setType(type);
//                log.setVoicemailUri(voicemailUri);
//                log.setGeocodedLocation(geo);
//                log.setCountryIso(iso);
//                log.setPhoneAccountId(imsi);
                mData.add(number);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    protected int getMsgWhat() {
        return 100002;
    }
}































































